package com.maoye.ossp.sys.quartz.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hotent.base.api.query.QueryFilter;
import com.hotent.base.api.query.QueryOP;
import com.maoye.ossp.common.entity.Page;
import com.maoye.ossp.common.web.BaseController;
import com.maoye.ossp.sys.quartz.entity.SysQuartzJob;
import com.maoye.ossp.sys.quartz.entity.SysQuartzLog;
import com.maoye.ossp.sys.quartz.service.QuartzLogService;

@Controller()
@RequestMapping(value = "sys/quartz/log")
public class QuartzLogController extends BaseController {
	
	@Resource
	private  QuartzLogService service;
	
	@RequestMapping(value = "getLogByID")
	public String getLogByID(HttpServletRequest request, HttpServletResponse response, Long id, ModelMap modelMap) {
		SysQuartzLog log = service.getLogByID(id);
		modelMap.put("log", log);
		return "/sys/quartz/logView";
	}
	
	@RequestMapping(value="showListByJobID")
	public String showListByJobID(HttpServletRequest request, HttpServletResponse response, Long job_id, Model model) {
		SysQuartzLog log = new SysQuartzLog();
		QueryFilter queryFilter = getQuerFilter(request, log);
		queryFilter.addFilter("job_id", job_id, QueryOP.EQUAL);
		Page<SysQuartzLog> page = service.find(queryFilter);
		model.addAttribute("page", page);
		if(page.getList() != null & page.getList().size() > 0){
			model.addAttribute("job_id", page.getList().get(0).getJob_id());
		}
		return "/sys/quartz/logList";
	}
	
	@RequestMapping(value="delLog")
	public String delLog(HttpServletRequest request, HttpServletResponse response, String id, Long job_id, RedirectAttributes redirectAttributes, Model model) {
		String[] strId = id.split(",");
		for (int i = 0; i < strId.length; i++) {
			service.delLog(Long.parseLong(strId[i]));
		}
		addMessage(redirectAttributes, "删除数据成功");
		return "redirect:showListByJobID?job_id="+job_id;
	}
	
	
	@RequestMapping(value = "showIndex")
	public String showIndex(SysQuartzJob job, ModelMap map) {
		return "/sys/quartz/index";
	}
}
